// pages/home_page/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    autoplay: true,
    interval: 3000,
    duration: 300,
    swiper_list: [],
    order_list: [],
    theme_color: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this;
    if (options.q) {
      let url = decodeURIComponent(options.q);
      let brand = app.dlc.getUrlParam("brand", url);
      let brand_title = app.dlc.getUrlParam("brand_title", url)
      wx.setStorageSync('brand', brand)
      wx.setStorageSync('brand_title', brand_title)
    } else if (options.brand) {
      wx.setStorageSync('brand', options.brand)
      wx.setStorageSync('brand_title', options.brand_title)
    } else {
      if (!app.dlc.gain('brand')) {
        wx.setStorageSync('brand', 'n.tuku321.com')
        wx.setStorageSync('brand_title', '集轻松')
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.get_banner()
    this.get_photo_exposure()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.login({
      success: (res) => {
        // console.log(res.code)
      },
    })
    this.setcolor()
    this.getTabBar().init()
  },
  setcolor(){
    this.setData({
      theme_color: app.dlc.gain('theme_color')
    })
  },
  SunshineCenter() {
    wx.navigateTo({
      url: '/home/pages/SunshineCenter/index',
    })
  },
  TrialCalculation() {
    wx.navigateTo({
      url: '/home/pages/TrialCalculation/index',
    })
  },
  get_banner() {
    const that = this;
    app.wxRequest('/api/Adv/index', { position: 'home' }, function (res) {
      if (res.code == 200) {
        that.setData({
          swiper_list: res.data.content
        })
      } else {
        app.toast(res.message)
      }
    })
  },
  get_photo_exposure() {
    const that = this;
    app.wxRequest('/api/Share/index', {
      page: 1
    }, function (res) {
      if (res.code == 200) {
        that.setData({
          order_list: res.data
        })
      } else {
        app.toast(res.message)
      }
    })
  },
  go_address() {
    wx.navigateTo({
      url: '/personal_center/pages/addressManagement/index',
    })
  },
  package() {
    wx.setStorageSync('add', 1)
    wx.switchTab({
      url: '/pages/package/index',
    })
    app.globalData.tabbar_index=2
  },
  sucess() {
    this.setcolor()
    this.get_banner()
    this.get_photo_exposure()
    this.getTabBar().init()
  },
  place_an_order(){
    wx.switchTab({
      url: '/pages/package/index',
    })
    app.globalData.tabbar_index=1
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})